package com.example.smartg.utils;

import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.smartg.R;

public class ToastUtil {
    public static  Toast mToast;
    public static void success(Context context,String msg){
        if(mToast == null){
            mToast = new Toast(context);
        }
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.layout_toast,null);
        ImageView imageView = (ImageView) view.findViewById(R.id.toast_logo);
        imageView.setImageResource(R.drawable.successful);
        TextView textView = (TextView) view.findViewById(R.id.toast_msg);
        textView.setText(msg);
        mToast.setView(view);
        mToast.setDuration(Toast.LENGTH_LONG);
        mToast.show();
        // 获取屏幕高度
        mToast.setGravity(Gravity.TOP, 0, 30);
    }
    public static void error(Context context,String msg){
        if(mToast == null){
            mToast = new Toast(context);
        }
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.layout_toast,null);
        ImageView imageView = (ImageView) view.findViewById(R.id.toast_logo);
        imageView.setImageResource(R.drawable.error);
        TextView textView = (TextView) view.findViewById(R.id.toast_msg);
        textView.setText(msg);
        mToast.setGravity(Gravity.TOP, 0, 20);
        mToast.setView(view);
        mToast.setDuration(Toast.LENGTH_LONG);
        mToast.show();
    }
}
